import { 
    AllowNull, 
    AutoIncrement, 
    Column, 
    CreatedAt, 
    DataType, 
    Model, 
    PrimaryKey, 
    Table, 
    Unique, 
    UpdatedAt 
} from "sequelize-typescript";
const crypto = require("crypto");

@Table({
    tableName: "User"
})
export class User extends Model<User>{

    @PrimaryKey
    @AutoIncrement
    @Column
    id: number;

    @AllowNull(false)
    @Unique(true)
    @Column({
        type: DataType.STRING(50)
    })
    name: string;

    @Column
    set password(val:string){
        let md5 = crypto.createHash("md5");
        let newPassword = md5.update(val).digest("hex");
        this.setDataValue("password", newPassword)
    };

    @CreatedAt
    createAt: Date;

    @UpdatedAt
    updatedAt: Date;
}